#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :get_category_list.py
# @Time      :2023/10/16 
# @Author    :CL
# @email     :1037654919@qq.com

import requests
from utils import mongo_manager,get_proxy
def get_category_list():
    headers = {
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Cache-Control": "no-cache",
        "Connection": "keep-alive",
        "Pragma": "no-cache",
        "Referer": "https://jinghecx.com/responsive/list?subCategoryId=13201",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
        "X-Requested-With": "XMLHttpRequest",
        "responsive-org": "clcn",
        "responsive-session-id": "",
        "sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Linux\""
    }
    url = "https://jinghecx.com/api/responsive/category-list"
    response = requests.get(url, headers=headers,proxies=get_proxy())

    # print(response.text)
    print(response)
    return response.json()


if __name__ == '__main__':

    qq_category_list = mongo_manager('qq_category_list')

    category_list  = get_category_list()
    # print(category_list)
    datas = category_list['data']
    for data in datas:
        data['_id'] = data["id"]
        try:
            qq_category_list.insertOne(data)
        except Exception as e:
            qq_category_list.updateOne({"_id": data['_id']}, data)

    qq_category_list.close()